/**
* Created by yyr on 2018/1/10
*已设立基金》选项卡基本信息
*/
<template>
    <div>
        <div class="ca-box-border-top-none ca-p-22">
            <el-col :span="12" class="ca-title clearfix">
                <h3>基本信息</h3>
            </el-col>
            <el-col :span='12' class="ca-align-right">
                <div>
                    <el-button type="primary" @click="saveFundBasic()" size="medium">保存</el-button>
                    <el-button  @click="cancel()" size="medium">取消</el-button>
                </div>
            </el-col>
            <el-form label-width="200px" class="ca-m-t-55">
                <el-row>
                    <el-col :span="11">
                        <el-form-item label="管理类型">
                            <el-select v-model="fundData.fundEst.manType" placeholder="请选择" style="width: 100%">
                                <el-option
                                    v-for="item in initView.fundManType"
                                    :label="item.name"
                                    :key="item.id"
                                    :value="item.id">
                                </el-option>
                            </el-select>
                        </el-form-item>
                    </el-col>
                    <el-col :span="11">
                        <el-form-item label="管理形式">
                            <el-select v-model="fundData.fundEst.fundForm" placeholder="请选择" style="width: 100%">
                                <el-option
                                    v-for="item in initView.fundForm"
                                    :label="item.name"
                                    :key="item.id"
                                    :value="item.id">
                                </el-option>
                            </el-select>
                        </el-form-item>
                    </el-col>
                </el-row>
                <el-row>
                    <el-col :span="11">
                        <el-form-item label="管理公司">
                            <el-input v-model="fundData.fundEst.company" placeholder="请输入内容" :maxlength="300"></el-input>
                        </el-form-item>
                    </el-col>
                    <el-col :span="11">
                        <el-form-item label="执行事务合伙人">
                            <el-select v-model="fundData.fundEst.partnerName"
                                       @change="changePartnerName"
                                       filterable placeholder="请选择" style="width:100%;">
                                <el-option
                                    v-for="item in userOptions"
                                    :key="item.value"
                                    :label="item.label"
                                    :value="item.value">
                                </el-option>
                            </el-select>
                        </el-form-item>
                    </el-col>
                </el-row>
                <el-row>
                    <el-col :span="11">
                        <el-form-item label="基金委派代表">
                            <el-input v-model="fundData.fundEst.fundDelegate" placeholder="请输入内容" :maxlength="300"></el-input>
                        </el-form-item>
                    </el-col>
                    <el-col :span="11">
                        <el-form-item label="基金托管人">
                            <el-input placeholder="请输入内容" v-model="fundData.fundEst.custodian" :maxlength="300"></el-input>
                        </el-form-item>
                    </el-col>
                </el-row>
                <el-row>
                    <el-col :span="11">
                        <el-form-item label="注册地">
                            <el-input placeholder="请输入内容" v-model="fundData.fundEst.place" :maxlength="100"></el-input>
                        </el-form-item>
                    </el-col>
                    <el-col :span="11">
                        <el-form-item label="办公地" >
                            <el-input placeholder="请输入内容" v-model="fundData.fundEst.officeLand" :maxlength="100"></el-input>
                        </el-form-item>
                    </el-col>
                </el-row>
                <el-row>
                    <el-col :span="11">
                        <el-form-item label="统一信用代码">
                            <el-input placeholder="请输入内容" v-model="fundData.fundEst.creditCode" :maxlength="300"></el-input>
                        </el-form-item>
                    </el-col>
                    <el-col :span="11">
                        <el-form-item label="投资决策委员会">
                            <el-row>
                                <el-select v-model="committeeName"
                                           @change="changeCommitteeName"
                                           filterable placeholder="请选择" style="width:100%;">
                                    <el-option
                                        v-for="item in userOptions"
                                        :key="item.value"
                                        :label="item.label"
                                        :value="item.value">
                                    </el-option>
                                </el-select>
                            </el-row>
                            <div>
                                <el-tag
                                    v-for="item in fundData.fundCommitteeList"
                                    :key="item.id"
                                    :closable="true"
                                    :close-transition="false"
                                    @close="closeCommitteeItem(item)"
                                    :type="item.type" class="ca-m-r-10">
                                    {{item.committeeName}}
                                </el-tag>
                            </div>
                        </el-form-item>
                    </el-col>
                </el-row>
                <el-row>
                    <el-col :span="11">
                        <el-form-item label="信息披露">
                            <el-input v-model="fundData.fundEst.disclosure"  :maxlength="3000" placeholder="请输入内容"></el-input>
                        </el-form-item>
                    </el-col>
                    <el-col :span="11">
                        <el-form-item label="管理费">
                            <el-input v-model="fundData.fundEst.proportion" :maxlength="3000" placeholder="请输入内容"></el-input>
                        </el-form-item>
                    </el-col>
                </el-row>
                <el-row>
                    <el-col :span="22">
                        <el-form-item label="投资限制">
                            <el-input v-model="fundData.fundEst.restrictions"  :maxlength="3000" type="textarea" placeholder="请输入内容"></el-input>
                        </el-form-item>
                    </el-col>
                </el-row>
                <el-row>
                    <el-col :span="22">
                        <el-form-item label="收益分配">
                            <el-input v-model="fundData.fundEst.distribution" :maxlength="3000" type="textarea"  placeholder="请输入内容"></el-input>
                        </el-form-item>
                    </el-col>
                </el-row>
                <el-row>
                    <el-col :span="22">
                        <el-form-item label="其他">
                            <el-input v-model="fundData.fundEst.other" type="textarea" :maxlength="3000" placeholder="请输入内容"></el-input>
                        </el-form-item>
                    </el-col>
                </el-row>
            </el-form>
        </div>
    </div>
</template>

<script type="text/ecmascript-6">
    import {api} from '../api';
    import {STATUS_HTTP_SUCCESS, apiHttp} from '__service/csHttp'
    export default {
        data() {
            return {
                itemId: this.$route.params.fundId,
                initView: {
                    fundManType: this.$store.state.user.dictionaryMap.fundManType,//管理类型
                    fundForm: this.$store.state.user.dictionaryMap.fundForm,//管理形式
                    userEntityList: this.$store.state.user.department.userEntityList,//用户
                },
                fundData: {
                    fundCommitteeList: [],
                    fundEst: {
                        backups: '1',  //是否备份
                        company: '', //管理公司
                        creditCode: '', //统一信用代码
                        disclosure: '',  //信息披露
                        distribution: '', //收益分配
                        exitMode: '', //退出方式
                        fundDelegate: '', //基金委派代表
                        fundForm: '1', //管理形式
                        fundId: this.$route.params.fundId,
                        id: '',
                        manType: '1', //管理类型 fundManType
                        other: '', //其他
                        partnerId: '', //执行事务合伙人id
                        partnerName: '', //执行事务合伙人名称
                        place: '', //注册地
                        proportion: '', //管理费比例
                        restrictions: '', //投资限制
                        officeLand: '',//办公地
                        custodian: '',//基金托管人
                    },
                },
                userOptions: [],
                partnerName: '',//执行事务合伙人name
                committeeName: '',//委员会的Name
                committeeNameList: [],//管理委员会数组
            }
        },
        props: [

        ],
        created() {
            this.getBasicDetail();
        },
        mounted() {
            this.userOptions = this.initView.userEntityList.map(item => {
                return { value: item.id, label: item.userName };
            });
        },
        methods: {
            getBasicDetail() {
                apiHttp(api.BASIC_DETAIL,{fundId: this.itemId}).then( ret=>{
                    if (ret.resCode === STATUS_HTTP_SUCCESS) {
                        this.fundBasicData = ret.data;
                        this.fundData.fundEst = ret.data.fundEst;
                        this.fundData.fundCommitteeList = ret.data.fundCommitteeList;
                    }
                })
            },
            saveFundBasic() {
                apiHttp(api.DETAIL_CHANGE,this.fundData).then( ret=>{
                    if (ret.resCode === STATUS_HTTP_SUCCESS) {
                        this.$message({
                            message: '修改成功',
                            type: 'success',
                            center: true
                        });
                        this.$emit('addRedDot')
                        this.cancel();
                    }
                })
            },
            cancel() {
                this.$emit('isEdit',false)
            },
            //关闭投资决策委员会
            closeCommitteeItem(tag) {
                this.fundData.fundCommitteeList.splice(this.fundData.fundCommitteeList.indexOf(tag),1);
            },
            //执行事务合伙人change
            changePartnerName(val) {
                let name = '';
                this.initView.userEntityList.map( item=> {
                    if (item.id === val) {
                        name = item.userName
                    }
                })
                this.fundData.fundEst.partnerName = name;
                this.fundData.fundEst.partnerId = val;
            },
            //投资决策委员会change
            changeCommitteeName(val) {
                let flag = false;
                for (let i of this.fundData.fundCommitteeList) {
                    if (i.id === val) {
                        flag = true;
                        return;
                    }
                }
                if (!flag) {
                    for (let i of this.userOptions) {
                        if (val === i.value) {
                            this.fundData.fundCommitteeList.push({committeeId: i.value,committeeName: i.label,fundId: this.itemId,id: ''})
                        }
                    }
                }
            }
        },
        components: {
        },
    }
</script>
<style rel="stylesheet/scss" lang="scss" scoped>
    .ca-m-t-55{
        margin-top:55px;
    }
</style>
